//
//  SelectFriendController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/20.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "SelectFriendController.h"
#import "SelectFriendView.h"
#import "FriendDataCenter.h"

@interface SelectFriendController ()<SelectFriendViewDelegate>

@property (nonatomic, strong) SelectFriendView *selectFriendView;
@property (nonatomic, strong) FriendDataCenter *dataCenter;

@end

@implementation SelectFriendController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.baseTitle = @"选择好友";
    self.rightBtnTitle = @"返回";
    
    _dataCenter = [FriendDataCenter new];
    
    [self makeSelectFriendView];
}

- (void)makeSelectFriendView
{
    _selectFriendView = [[SelectFriendView alloc]init];
    _selectFriendView.delegate = self;
    [self.baseView addSubview:_selectFriendView];
    [_selectFriendView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
}

- (void)headerWithRefreshingData
{
    [self loadFriendListData];
}

- (void)loadFriendListData
{
    [_dataCenter fetchFriendListComplation:^(id responseObject, NSString *error) {
        if (error == nil) {
            _selectFriendView.listData = (NSArray *)responseObject;
        }else{
            [YJProgressHud showErrorHud:error];
        }
    }];
}

- (void)didSelectFriend:(FriendModel *)friendModel
{
    [self dismissViewControllerAnimated:NO completion:nil];
    if ([self.delegate respondsToSelector:@selector(didSelectIndexWithFriend:)]) {
        [self.delegate didSelectIndexWithFriend:friendModel];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
